﻿
var currentProduct;
var touchEndEvent;

$(document).ready(function () {

    //g5.init();
    touchEndEvent = "ontouchend" in document ? "touchend" : "mouseup";

    $(".shop-to-buy").bind(touchEndEvent, move_From_Shoptobuy_To_Cart);
    $(".shop-in-cart").bind(touchEndEvent, move_From_ShopInCart_To_Buy);
    $("#btnSaveProduct").bind(touchEndEvent, saveProductChange);
    $("#btnCancelProduct").bind(touchEndEvent, cancelProductChange);
    //$(".prodToEdit").bind(touchEndEvent, showProductChange);

    // fillSampleTemplate();
    
});

//function showProductChange(e) {
//    e.preventDefault();
//    currentProduct = $(this);
//    $("#popPrepareProduct").data("kendoMobilePopOver").openFor(this);
//    alert("FFFF = " + $(currentProduct).next().text());
//    $("#txtChangeProductName").val($(currentProduct).text());
//    $("#txtChangeProductAmount").val($(currentProduct).next().text());

//}

function cancelProductChange(e) {
    $("#popPrepareProduct").data("kendoMobilePopOver").close();
}

function saveProductChange(e) {
    var prodName = $("#txtChangeProductName").val();
    var prodCount = $("#txtChangeProductAmount").val();
    var prodToBuy = $("#txtChangeProductToBuy").data("kendoMobileSwitch").check();
    $("#popPrepareProduct").data("kendoMobilePopOver").close();
    //alert("product '" + prodName + "' in '" + prodCount + "' is " + prodToBuy);
    $(currentProduct).next().text(prodToBuy);
    $(currentProduct).next().next().text(prodCount);
    $(currentProduct).text(prodName);
}
function move_From_Shoptobuy_To_Cart(e) {
    e.preventDefault();
    //alert($(this).parent().attr('id'));
    $(this).parent().prependTo('#shop-in-cart');
    $(this)
			.removeClass('shop-to-buy')
			.addClass('shop-in-cart');
    $(this).unbind(e);
    $(this).bind(touchEndEvent, move_From_ShopInCart_To_Buy);
}
function move_From_ShopInCart_To_Buy(e) {
    e.preventDefault();
    //alert(destPage);
    $(this).parent().prependTo('#shop-to-buy');
    $(this)
			.removeClass('shop-to-buy')
			.addClass('shop-in-cart');
    $(this).unbind(e);
    $(this).bind(touchEndEvent, move_From_Shoptobuy_To_Cart);
}

//function fillSampleTemplate() {
//    var dataSource = new kendo.data.DataSource({
//        transport: {
//            read: {
//                url: "http://search.twitter.com/search.json",
//                contentType: "application/json; charset=utf-8",
//                type: "GET",
//                dataType: "jsonp",
//                data: {
//                    q: "#KendoUI"
//                }
//            }
//        },
//        schema: {
//            data: "results",
//            total: "results_per_page"
//        }
//    });

//    $("#listView").kendoListView({
//        dataSource: dataSource,
//        template: kendo.template($("#template").html())
//    });

//}

